package routes

import (
	"gitee.com/igolang/imoney/internal/app/system/controllers"
	"gitee.com/igolang/imoney/internal/app/system/entities"
	"gitee.com/igolang/imoney/internal/app/system/entities/constants"
	"gitee.com/igolang/pkg/xgin"
)

func (r *router) monitor() {
	g := &xgin.RouterGroup{Name: "系统监控", Group: r.mg.Group("")}
	g.GET(xgin.RouteInfo{
		Name: "服务监控",
		Path: "server",
		Ext: &entities.RoutePerm{
			Permission: "monitor:server:list",
			Token:      true,
		},
	}, controllers.Monitor.Server)
	r.job()
	r.jobLog()
	r.online()
}

// online 在线用户
func (r *router) online() {
	g := &xgin.RouterGroup{Name: "在线用户", Group: r.mg.Group("online")}
	g.GET(xgin.RouteInfo{
		Name: "在线用户列表",
		Path: "list",
		Ext: &entities.RoutePerm{
			Permission:       "monitor:online:list",
			Token:            true,
			OperationLogType: 0,
		},
	}, controllers.Monitor.OnlineList)

	g.DELETE(xgin.RouteInfo{
		Name: "用户强退",
		Path: ":id",
		Ext: &entities.RoutePerm{
			Permission:       "monitor:online:forceLogout",
			Token:            true,
			OperationLogType: constants.OperationLogOut,
		},
	}, controllers.Monitor.OnlineQuit)
}

// job 任务管理
func (r *router) job() {
	g := &xgin.RouterGroup{Name: "定时任务", Group: r.mg.Group("job")}
	g.GET(xgin.RouteInfo{
		Name: "任务列表",
		Path: "list",
		Ext: &entities.RoutePerm{
			Permission: "monitor:job:list",
			Token:      true,
		},
	}, controllers.Monitor.JobList)

	g.POST(xgin.RouteInfo{
		Name: "导出任务",
		Path: "export",
		Ext: &entities.RoutePerm{
			Permission:       "monitor:job:export",
			Token:            true,
			OperationLogType: constants.OperationLogExport,
		},
	}, controllers.Monitor.JobExport)

	g.GET(xgin.RouteInfo{
		Name: "任务详情",
		Path: ":id",
		Ext: &entities.RoutePerm{
			Permission: "monitor:job:query",
			Token:      true,
		},
	}, controllers.Monitor.JobDetail)

	g.POST(xgin.RouteInfo{
		Name: "新增任务",
		Ext: &entities.RoutePerm{
			Permission:       "monitor:job:add",
			Token:            true,
			OperationLogType: constants.OperationLogAdd,
		},
	}, controllers.Monitor.JobSave)

	g.PUT(xgin.RouteInfo{
		Name: "编辑任务",
		Ext: &entities.RoutePerm{
			Permission:       "monitor:job:edit",
			Token:            true,
			OperationLogType: constants.OperationLogUpdate,
		},
	}, controllers.Monitor.JobSave)

	g.DELETE(xgin.RouteInfo{
		Name: "删除任务",
		Path: ":ids",
		Ext: &entities.RoutePerm{
			Permission:       "monitor:job:remove",
			Token:            true,
			OperationLogType: constants.OperationLogRemove,
		},
	}, controllers.Monitor.JobDelete)

	g.PUT(xgin.RouteInfo{
		Name: "修改任务状态",
		Path: "changeStatus",
		Ext: &entities.RoutePerm{
			Permission:       "monitor:job:changeStatus",
			Token:            true,
			OperationLogType: constants.OperationLogUpdate,
		},
	}, controllers.Monitor.JobChangeStatus)

	g.PUT(xgin.RouteInfo{
		Name: "执行任务",
		Path: "run",
		Ext: &entities.RoutePerm{
			Permission:       "monitor:job:run",
			Token:            true,
			OperationLogType: constants.OperationLogUpdate,
		},
	}, controllers.Monitor.JobRun)
}

// jobLog 任务日志管理
func (r *router) jobLog() {
	g := &xgin.RouterGroup{Name: "定时任务日志", Group: r.mg.Group("jobLog")}
	g.GET(xgin.RouteInfo{
		Name: "任务日志列表",
		Path: "list",
		Ext: &entities.RoutePerm{
			Permission: "monitor:job:query",
			Token:      true,
		},
	}, controllers.Monitor.JobLogList)

	g.POST(xgin.RouteInfo{
		Name: "任务日志导出",
		Path: "export",
		Ext: &entities.RoutePerm{
			Permission:       "monitor:job:export",
			Token:            true,
			OperationLogType: constants.OperationLogExport,
		},
	}, controllers.Monitor.JobLogExport)

	g.DELETE(xgin.RouteInfo{
		Name: "任务日志删除",
		Path: ":ids",
		Ext: &entities.RoutePerm{
			Permission:       "monitor:job:remove",
			Token:            true,
			OperationLogType: constants.OperationLogRemove,
		},
	}, controllers.Monitor.JobLogDelete)

	g.DELETE(xgin.RouteInfo{
		Name: "任务日志清空",
		Path: "clean",
		Ext: &entities.RoutePerm{
			Permission:       "monitor:job:remove",
			Token:            true,
			OperationLogType: constants.OperationLogClean,
		},
	}, controllers.Monitor.JobLogClean)
}

// log 日志管理
func (r *router) log() {
	operLogG := &xgin.RouterGroup{Name: "操作日志", Group: r.mg.Group("operlog")}
	operLogG.GET(xgin.RouteInfo{
		Name: "日志列表",
		Path: "list",
		Ext: &entities.RoutePerm{
			Token:      true,
			Permission: "monitor:operlog:list",
		},
	}, controllers.OperLog.List)
	operLogG.DELETE(xgin.RouteInfo{
		Name: "删除操作日志",
		Path: ":ids",
		Ext: &entities.RoutePerm{
			Token:            true,
			Permission:       "monitor:operlog:remove",
			OperationLogType: constants.OperationLogRemove,
		},
	}, controllers.OperLog.Delete)
	operLogG.DELETE(xgin.RouteInfo{
		Name: "清空操作日志",
		Path: "clean",
		Ext: &entities.RoutePerm{
			Token:            true,
			Permission:       "monitor:operlog:remove",
			OperationLogType: constants.OperationLogClean,
		},
	}, controllers.OperLog.Clean)
	operLogG.POST(xgin.RouteInfo{
		Name: "导出操作日志",
		Path: "export",
		Ext: &entities.RoutePerm{
			Token:            true,
			Permission:       "monitor:operlog:export",
			OperationLogType: constants.OperationLogExport,
		},
	}, controllers.OperLog.Export)
	// 登录日志
	logininforG := &xgin.RouterGroup{Name: "登录日志", Group: r.mg.Group("logininfor")}
	logininforG.GET(xgin.RouteInfo{
		Name: "日志列表",
		Path: "list",
		Ext: &entities.RoutePerm{
			Token:      true,
			Permission: "monitor:logininfor:list",
		},
	}, controllers.Logininfor.List)

	logininforG.DELETE(xgin.RouteInfo{
		Name: "删除登录日志",
		Path: ":ids",
		Ext: &entities.RoutePerm{
			Token:            true,
			Permission:       "monitor:logininfor:remove",
			OperationLogType: constants.OperationLogRemove,
		},
	}, controllers.Logininfor.Delete)

	logininforG.DELETE(xgin.RouteInfo{
		Name: "清空登录日志",
		Path: "clean",
		Ext: &entities.RoutePerm{
			Token:            true,
			Permission:       "monitor:logininfor:remove",
			OperationLogType: constants.OperationLogClean,
		},
	}, controllers.Logininfor.Clean)

	logininforG.POST(xgin.RouteInfo{
		Name: "导出登录日志",
		Path: "export",
		Ext: &entities.RoutePerm{
			Token:            true,
			Permission:       "monitor:logininfor:export",
			OperationLogType: constants.OperationLogExport,
		},
	}, controllers.Logininfor.Export)
}
